<?php 
class Db_hotel extends CI_Model{
	public  function __construct(){
		parent::__construct();
	}
	
	public function attrac_listcat(){
		$config['base_url'] = base_url().'manage_attrac/attraction_cat';
		$config['total_rows'] = $this->db->count_all("hotel_local_attraction_category");
		$config['per_page'] = 20;
		$config['full_tag_open'] = '<div class="pages">';
		$config['full_tag_close'] = '<div>';
		$this->pagination->initialize($config);
		$this->db->limit($config['per_page'],$this->uri->segment(3));
		$this->db->order_by("pkid", "desc");
		$res = $this->db->get('hotel_local_attraction_category');
		//==
		$no = $this->uri->segment(3)+1;
		$i = 1;
		$arr = $res->result_array();
		$cat = array();
		foreach ($arr as $P){
			if($i %2 == 0)
				$tmp['back']							="#FFFFFF";
			else
				$tmp['back']							="#F4F4F4";
			$i++;
			$tmp['no']							=$no;
			$tmp['pkid']						=$P['pkid'];
			$tmp['name_en']				=$P['name_en'];
			$tmp['name_zh_cn']			=$P['name_zh_cn'];
			$tmp['name_th']					=$P['name_th'];
			$cat[] = $tmp;
			$no = $no+1;
		}
		$num_row = $config['total_rows'];
		$pagelink  = $this->pagination->create_links();
		return array($cat,$num_row,$pagelink,$config['total_rows']);
	}
	
	public function attrac_list(){
		$config['base_url'] = base_url().'manage_attrac/attraction_list';
		$config['total_rows'] = $this->db->count_all("hotel_local_attraction_item");
		$config['per_page'] = 20;
		$config['full_tag_open'] = '<div class="pages">';
		$config['full_tag_close'] = '<div>';
		$this->pagination->initialize($config);
		$this->db->from('hotel_local_attraction_category t1');
		$this->db->join('hotel_local_attraction_item t2', 't1.pkid = t2.category_pkid');
		$this->db->limit($config['per_page'],$this->uri->segment(3));
		$this->db->order_by("t2.pkid", "desc");
		$res = $this->db->get();
		//==
		$no = $this->uri->segment(3)+1;
		$i = 1;
		$arr = $res->result_array();
		$item = array();
		foreach ($arr as $P){
			if($i %2 == 0)
				$tmp['back']							="#FFFFFF";
			else
				$tmp['back']							="#F4F4F4";
			$i++;
			$tmp['no']							=$no;
			$tmp['pkid']						=$P['pkid'];
			$tmp['title_en']					=$P['title_en'];
			$tmp['name_en']				=$P['name_en'];
			$tmp['title_zh_cn']				=$P['title_zh_cn'];
			$tmp['title_th']					=$P['title_th'];
			$item[] = $tmp;
			$no = $no+1;
		}
		$num_row = $config['total_rows'];
		$pagelink  = $this->pagination->create_links();
		return array($item,$num_row,$pagelink,$config['total_rows']);
	}
	
	public function attract_show_cat($group=""){
		$this->db->order_by("pkid","desc");
		$res = $this->db->get('hotel_local_attraction_category');
		$str = '<option value="">=select category=</option>';
		foreach ($res->result_array() as $P){
			if($group == $P['pkid']){
				$check = 'selected="selected"';
			}else{ 
				$check = "";
			}
			$str .='<option value="'.$P['pkid'].'" '.$check.'>'.$P['name_en'].'</option>';
		}
		return $str;
	}
	
	public function meal_cat_list(){
		$config['base_url'] = base_url().'manage_meal/attraction_cat';
		$config['total_rows'] = $this->db->count_all("hotel_meal_category");
		$config['per_page'] = 20;
		$config['full_tag_open'] = '<div class="pages">';
		$config['full_tag_close'] = '<div>';
		$this->pagination->initialize($config);
		$this->db->limit($config['per_page'],$this->uri->segment(3));
		$this->db->order_by("pkid", "desc");
		$res = $this->db->get('hotel_meal_category');
		//==
		$no = $this->uri->segment(3)+1;
		$i = 1;
		$arr = $res->result_array();
		$cat = array();
		foreach ($arr as $P){
			if($i %2 == 0)
				$tmp['back']							="#FFFFFF";
			else
				$tmp['back']							="#F4F4F4";
			$i++;
			$tmp['no']							=$no;
			$tmp['pkid']						=$P['pkid'];
			$tmp['name_en']				=$P['name_en'];
			$tmp['name_zh_cn']			=$P['name_zh_cn'];
			$tmp['name_th']					=$P['name_th'];
			$cat[] = $tmp;
			$no = $no+1;
		}
		$num_row = $config['total_rows'];
		$pagelink  = $this->pagination->create_links();
		return array($cat,$num_row,$pagelink,$config['total_rows']);
	}
	
	public function news_item_list(){
		$config['base_url'] = base_url().'manage_news/news_list';
		$config['total_rows'] = $this->db->count_all("hotel_news");
		$config['per_page'] = 20;
		$config['full_tag_open'] = '<div class="pages">';
		$config['full_tag_close'] = '<div>';
		$this->pagination->initialize($config);
		$this->db->select('pkid,name_en,name_en');
		$this->db->from('hotel_news');
		$this->db->limit($config['per_page'],$this->uri->segment(3));
		$this->db->order_by("pkid", "desc");
		$res = $this->db->get();
		//==
		$no = $this->uri->segment(3)+1;
		$i = 1;
		$arr = $res->result_array();
		$item = array();
		foreach ($arr as $P){
			if($i %2 == 0)
				$tmp['back']							="#FFFFFF";
			else
				$tmp['back']							="#F4F4F4";
			$i++;
			$tmp['no']							=$no;
			$tmp['pkid']						=$P['pkid'];
			$tmp['title_en']					=$P['name_en'];
			$item[] = $tmp;
			$no = $no+1;
		}
		$num_row = $config['total_rows'];
		$pagelink  = $this->pagination->create_links();
		return array($item,$num_row,$pagelink,$config['total_rows']);
	}
	
	public function meal_show_cat($group=""){
		$this->db->order_by("pkid","desc");
		$res = $this->db->get('hotel_meal_category');
		$str = '<option value="">=select category=</option>';
		foreach ($res->result_array() as $P){
			if($group == $P['pkid']){
				$check = 'selected="selected"';
			}else{
				$check = "";
			}
			$str .='<option value="'.$P['pkid'].'" '.$check.'>'.$P['name_en'].'</option>';
		}
		return $str;
	}
	
	public function department_list(){
		$config['base_url'] = base_url().'manage_hotel/hotel_department';
		$config['total_rows'] = $this->db->count_all("hotel_department");
		$config['per_page'] = 20;
		$config['full_tag_open'] = '<div class="pages">';
		$config['full_tag_close'] = '<div>';
		$this->pagination->initialize($config);
		$this->db->limit($config['per_page'],$this->uri->segment(3));
		$this->db->order_by("pkid", "desc");
		$res = $this->db->get('hotel_department');
		//==
		$no = $this->uri->segment(3)+1;
		$i = 1;
		$arr = $res->result_array();
		$cat = array();
		foreach ($arr as $P){
			if($i %2 == 0)
				$tmp['back']							="#FFFFFF";
			else
				$tmp['back']							="#F4F4F4";
			$i++;
			$tmp['no']							=$no;
			$tmp['pkid']						=$P['pkid'];
			$tmp['name_en']				=$P['name_en'];
			$tmp['name_zh_cn']			=$P['name_zh_cn'];
			$tmp['name_th']					=$P['name_th'];
			$cat[] = $tmp;
			$no = $no+1;
		}
		$num_row = $config['total_rows'];
		$pagelink  = $this->pagination->create_links();
		return array($cat,$num_row,$pagelink,$config['total_rows']);
	}
	
	public function partner(){
		$config['base_url'] = base_url().'manage_hotel/partner_list';
		$config['total_rows'] = $this->db->count_all("hotel_partner");
		$config['per_page'] = 20;
		$config['full_tag_open'] = '<div class="pages">';
		$config['full_tag_close'] = '<div>';
		$this->pagination->initialize($config);
		$this->db->limit($config['per_page'],$this->uri->segment(3));
		$this->db->order_by("pkid", "desc");
		$res = $this->db->get('hotel_partner');
		//==
		$no = $this->uri->segment(3)+1;
		$i = 1;
		$arr = $res->result_array();
		$cat = array();
		foreach ($arr as $P){
			if($i %2 == 0)
				$tmp['back']							="#FFFFFF";
			else
				$tmp['back']							="#F4F4F4";
			$i++;
			$tmp['no']							=$no;
			$tmp['pkid']						=$P['pkid'];
			$tmp['name_en']				=$P['name'];
			$cat[] = $tmp;
			$no = $no+1;
		}
		$num_row = $config['total_rows'];
		$pagelink  = $this->pagination->create_links();
		return array($cat,$num_row,$pagelink,$config['total_rows']);
	}
	
	public function country_list($id=""){
		$this->db->order_by("name","asc");
		$res =$this->db->get("hotel_country");
		$str = '<option value="">=select country=</option>';
		foreach ($res->result_array() as $P){
			if($id == $P['pkid']) $ch = 'selected="selected"';
			else $ch="";
			$str .='<option value="'.$P['pkid'].'" '.$ch.'>'.$P['name'].'</option>';
		}
		return $str;
	}
	
	public function langs($L=""){
		$L1="";$L2="";$L3="";
		if($L == 1){
			$L1 = 'selected="selected"';
		}else if($L == 2){
			$L2 = 'selected="selected"';
		}else if($L == 3){
			$L3 = 'selected="selected"';
		}
		$str = '<option value="1" '.$L1.'>EN</option>"';
		$str .= '<option value="2" '.$L2.'>CN</option>"';
		$str .= '<option value="3" '.$L3.'>TH</option>"';
		return $str;
	}
	
	public function getRealIpAddr()
	{
		if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
		{
			$ip=$_SERVER['HTTP_CLIENT_IP'];
		}
		elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
		{
			$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
		}
		else
		{
			$ip=$_SERVER['REMOTE_ADDR'];
		}
		return $ip;
	}
	
}
?>